package traveler.activities;

import traveler.activities.R;
import traveler.controllers.CourseController;
import traveler.controllers.GoogleMapsController;
import traveler.controllers.StepController;
import traveler.models.Course;
import traveler.models.Step;
import android.content.Intent;
import android.os.Bundle;
import traveler.tools.ImageAdapter;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.TextView;

public class CourseActivity extends DashboardActivity
{
	private CourseController _controller;
	private static Course _course;
	
	public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.course);
        setTitleFromActivityLabel (R.id.title_text);
        
        _controller = new CourseController(CourseActivity.this);
        Bundle bundle = getIntent().getExtras();
        TextView lblQuestion = (TextView)findViewById(R.id.course_lblQuestion);
        
        if(bundle != null)
        {
        	TextView lblStepTitle = (TextView)findViewById(R.id.course_lblStepTitle);
        	EditText txtAnswer = (EditText)findViewById(R.id.course_txtAnswer);
        	
        	lblStepTitle.setText(bundle.getString(StepController.TITLE));
        	txtAnswer.setText(bundle.getString(StepController.ANSWER));
        	txtAnswer.setEnabled(false);
        	lblQuestion.setText(bundle.getString(StepController.QUESTION));
        }
        else
        {
            Step step = new Step(this);
            step.setQuestion(getString(R.string.question_eiffel));
            lblQuestion.setText(step.getQuestion());
        }
        
        Button btnSubmit = (Button)findViewById(R.id.course_btnSubmit);
        btnSubmit.setOnClickListener(_controller);
        
        Gallery gallery = (Gallery) findViewById(R.id.course_gallery);
        gallery.setAdapter(new ImageAdapter(this, new int[] { R.drawable.tour_eiffel, R.drawable.tour_eiffel, R.drawable.tour_eiffel, R.drawable.tour_eiffel, R.drawable.tour_eiffel }));
        gallery.setOnItemClickListener(_controller);
    }
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.course, menu);
 
        return true;
     }
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		boolean isSelected = false;
		
		switch (item.getItemId())
		{
			case R.id.menu_course_steps:
				startActivity(new Intent(this, StepsListActivity.class));
				isSelected = true;
				break;
			case R.id.menu_course_map:
				Intent intent = new Intent(this, GoogleMapsActivity.class);
				Bundle bundle = new Bundle();
				
				bundle.putInt(GoogleMapsController.LATITUDE, Step.PARIS.getLatitudeE6());
				bundle.putInt(GoogleMapsController.LONGITUDE, Step.PARIS.getLongitudeE6());
				intent.putExtras(bundle);
				
				startActivity(intent);
				isSelected = true;
				break;
			case R.id.menu_course_qrcode:
				startActivity(new Intent(this, QRCodeActivity.class));
				isSelected = true;
				break;
		}
		
		return isSelected;
	}
}
